<template>
  <el-container class="main_container">
    <!--头部布局-->
    <el-header>
      <!--logo和项目名称-->
      <div class="left_box">
        <img src="../assets/demo.jpeg">
        <span>药物管理系统</span>
      </div>
      <div style="margin-left: 1100px">{{this.name}}</div>
      <!--用户登录展示的头像-->
      <div class="right_box">
        <el-dropdown>
          <img src="../assets/demo.jpeg">
          <!--下拉菜单-->
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-house">系统首页</el-dropdown-item>
<!--            <el-dropdown-item icon="el-icon-ship">交流讨论</el-dropdown-item>-->
            <el-dropdown-item icon="el-icon-switch-button" @click.native="unlogin" >退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <!--侧边栏-->
      <el-aside :width="isCollapse?'64px':'200px'">
        <!--展开/收起-->
        <div class="toggle_box" @click="toggleCollapse">|||</div>
        <el-menu
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#001529"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse"
          :default-active="activePath"
          :collapse-transition="false"
          :unique-opened="true"
          :router="true">
          <MenuTree :menuList="this.MenuList"></MenuTree>
        </el-menu>
      </el-aside>
      <el-main>
        <!--路由视图-->
        <router-view v-if="isRouterAlive"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import MenuTree from '../components/MenuTree'

  export default {
    name: 'Main',
    provide()
    {
      return{
        reload:this.reload
      }
    },
    data () {
      return {
        isCollapse: false,
        activePath: '',
        isRouterAlive:true,
        name:window.localStorage.getItem('name'),
        MenuList: [
          {
            "id": 1,
            "parentId": 0,
            "menuName": "系统管理",
            "url": "",
            "icon": "el-icon-setting",
            "orderNum": 1,
            "open": 1,
            "disabled": false,
            "perms": null,
            "type": 0,
            "children": [
              {
                "id": 226,
                "parentId": 1,
                "menuName": "系统首页",
                "url": "/main/homepage",
                "icon": "el-icon-house",
                "orderNum": 1,
                "open": 0,
                "disabled": false,
                "perms": "users",
                "type": 0,
                "children": []
              },
              {
                "id": 226,
                "parentId": 1,
                "menuName": "个人信息",
                "url": "/main/PersonInfo",
                "icon": "el-icon-chat-dot-round",
                "orderNum": 1,
                "open": 0,
                "disabled": false,
                "perms": "users",
                "type": 0,
                "children": []
              },
              {
                "id": 226,
                "parentId": 1,
                "menuName": "员工管理",
                "url": "/main/InfoManage",
                "icon": "el-icon-user",
                "orderNum": 1,
                "open": 0,
                "disabled": false,
                "perms": "users",
                "type": 0,
                "children": []
              },
              {
                "id": 319,
                "parentId": 1,
                "menuName": "公告管理",
                "url": "/main/notices",
                "icon": "el-icon-s-flag",
                "orderNum": 4,
                "open": 0,
                "disabled": false,
                "perms": "",
                "type": 0,
                "children": []
              }
            ]
          },
          {
            "id": 312,
            "parentId": 0,
            "menuName": "供应商管理",
            "url": null,
            "icon": "el-icon-s-goods",
            "orderNum": 2,
            "open": 0,
            "disabled": false,
            "perms": null,
            "type": 0,
            "children": [
              {
                "id": 313,
                "parentId": 312,
                "menuName": "供应商信息",
                "url":"/provider/ProviderInfo",
                "icon": "el-icon-edit",
                "orderNum": 1,
                "open": 0,
                "disabled": false,
                "perms": null,
                "type": 0,
                "children": [
                ]
              }
            ]
          },
          {
            "id": 303,
            "parentId": 0,
            "menuName": "药物管理",
            "url": "",
            "icon": "el-icon-burger",
            "orderNum": 3,
            "open": 0,
            "disabled": false,
            "perms": "",
            "type": 0,
            "children": [
              {
                "id": 272,
                "parentId": 303,
                "menuName": "药物信息",
                "url": "/medicine/MedicineInfo",
                "icon": "el-icon-help",
                "orderNum": 5,
                "open": 0,
                "disabled": false,
                "perms": null,
                "type": 0,
                "children": []
              },
              {
                "id": 272,
                "parentId": 303,
                "menuName": "药物购买",
                "url": "/medicine/MedicineBuy",
                "icon": "el-icon-shopping-cart-1",
                "orderNum": 5,
                "open": 0,
                "disabled": false,
                "perms": null,
                "type": 0,
                "children": []
              },
              {
                "id": 272,
                "parentId": 303,
                "menuName": "我的订单",
                "url": "/medicine/OrderInfo",
                "icon": "el-icon-tickets",
                "orderNum": 5,
                "open": 0,
                "disabled": false,
                "perms": null,
                "type": 0,
                "children": []
              }
            ]
          },
          {
            "id": 5,
            "parentId": 0,
            "menuName": "日志管理",
            "url": "/logs",
            "icon": "el-icon-camera",
            "orderNum": 6,
            "open": 0,
            "disabled": false,
            "perms": null,
            "type": 0,
            "children": [
              {
                "id": 271,
                "parentId": 5,
                "menuName": "登入日志",
                "url": "/loginLog",
                "icon": "el-icon-date",
                "orderNum": 1,
                "open": 0,
                "disabled": false,
                "perms": "login:log",
                "type": 0,
                "children": []
              },
              {
                "id": 307,
                "parentId": 5,
                "menuName": "操作日志",
                "url": "/logs",
                "icon": "el-icon-edit",
                "orderNum": 1,
                "open": 1,
                "disabled": false,
                "perms": "",
                "type": 0,
                "children": []
              }
            ]
          }
        ]
      }
    },
    components: {
      MenuTree
    },
    methods: {
      reload(){
        this.isRouterAlive=false;
        this.$nextTick(function () {
          this.isRouterAlive=true
        })
      },
      toggleCollapse () {
        this.isCollapse = !this.isCollapse
      },
      unlogin(){
        this.$router.push({path:"/"})
        // window.localStorage.removeItem("id")
        // window.localStorage.removeItem("remark")
        // window.localStorage.removeItem("token")
        // window.localStorage.removeItem("name")
        window.localStorage.clear();
      },
      handleOpen (key, keyPath) {
        console.log(key, keyPath)
      },
      handleClose (key, keyPath) {
        console.log(key, keyPath)
      },
      created:function () {
        this.$router.push({path:"/welcome"})
      }
    }
  }
</script>

<style lang="less" scoped>
  /*设置整个容器的高度*/
  .main_container {
    margin: 0;
    padding: 0;
    height: 100vh;
    //background-color: azure;
  }

  /*头部布局*/
  .el-header {
    background-color: #001529;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    color: #FFFFFF;
    align-items: center;
    font-size: 20px;

    /*左边logo和标题*/

    .left_box {
      display: flex;
      align-items: center;

      /*logo*/

      img {
        width: 60px;
        height: 60px;
        margin: 0px 0px 10px 15px;
      }

      /*标题*/

      span {
        margin-left: 15px;
      }
    }

    /*右边的登录头像*/

    .right_box {
      .el-dropdown > img {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        background-color: #FFFFFF;
        margin: 0px 15px 0px 0px;
        background-size: contain;
      }
    }
  }

  /*侧边栏*/
  .el-aside {
    background-color: #001529;

    .el-menu {
      border-right: none;
    }

    /*展开/收起*/

    .toggle_box {
      background-color: chartreuse;
      font-size: 15px;
      font-weight: bold;
      line-height: 24px;
      color: #FFFFFF;
      letter-spacing: 0.2em;
      text-align: center;
      cursor: pointer;

    }
  }

  /*内容主体*/
  .el-main {
   background-color: white;
  }

  /*下拉菜单的样式*/
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
</style>
